


// 安装axios
// $cnpm i axios -S
// webserver接口 端口号：8080
import axios from "axios";
// 创建axios初始化
// https://apis.netstart.cn/music/user/followeds?uid=32953014

// var url = '192.168.124.150' 
var apiUrl = window.location.href.match(/(.+#)/)
var baseURL = ''
// 	if(apiUrl){
//        baseURL = apiUrl[0].replace(/#/g, "")
// 	}else {
// 		baseURL =  window.location.href
// }
var url = window.location.host.split(':')[0];//页面路径
baseURL = `http://${url}:8088`
// baseURL = `http://192.168.1.187:8088`
  // baseURL = 'http://192.168.1.87:8088'
// localStorage.setItem("baseURL", baseURL)
// console.log("baseURL",baseURL);
// baseURL = 'http://192.168.124.198:8080'

const service = axios.create({
  baseURL: baseURL,
  // baseURL: '/api',
  timeout: 5400000, //超时时间
  headers: {
    "Content-Type": "application/json;charset=utf-8", //表单数据转化
  },
  withCredentials: true,
});


// request 拦截器 发送数据到后台前拦截
service.interceptors.request.use(
  (config) => {
    const d = localStorage.getItem('userDetailed');
    if (d) {
      let t = JSON.parse(d);
      config.headers['token'] = t.pkid;
      config.headers['content-type'] = 'application/json';
    }
    return config;
  },
  (error) => {
    console.log("axios中request报错", error);
    Promise.reject(error);
  }
);


// response 拦截器 获取后台数据前拦截
service.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (error) => {
    console.log("axios中response报错", error);
    Promise.reject(error);
  }
);
export default service;
